package com.gw.smscheck.service.sys.impl;

import com.alibaba.fastjson.support.odps.CodecCheck;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.gw.smscheck.dao.sys.DataDictionaryMapper;
import com.gw.smscheck.entity.sys.DataDictionary;
import com.gw.smscheck.service.sys.DataDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class DataDictionaryImpl implements DataDictionaryService {
	
	@Autowired
	private DataDictionaryMapper dataDictionaryMapper;
	
	/**
	 * 分页查询
	 * @param
	 * @return
	 */
	@Override

	public List<DataDictionary> pageSelect(DataDictionary dto) {
		List< DataDictionary> resultList =new ArrayList<>();
		DataDictionary dataDictionary = new DataDictionary();

		if(!"".equals(dto.getName()) && dto !=null){
			PageHelper.startPage(dto.getPage(),dto.getRows(),"sort asc");
			List<DataDictionary> list = new ArrayList<>();
			list=dataDictionaryMapper.parentRecord(dto);

			//查询子节点
			List<DataDictionary>  list1= new ArrayList<>();
			list1=	dataDictionaryMapper.getChildrenById(list.get(0));
			for(int i = 0;i < list1.size();i ++){
				list.add(list1.get(i));
			}
			resultList =list;

		}	else{
			PageHelper.startPage(dto.getPage(), dto.getRows(), "sort asc");
			resultList = dataDictionaryMapper.pageSelect(dto);
		}

		return resultList;
	}
/*	public PageInfo<DataDictionary> pageSelect(DataDictionary dto){
		PageHelper.startPage(dto.getPage(),dto.getRows(),"createtime desc");
		List<DataDictionary> resultList = dataDictionaryMapper.pageSelect(dto);
		//查询子节点
		for(DataDictionary dataDictionary : resultList){
			dataDictionary.setChildren(dataDictionaryMapper.getChildrenById(dataDictionary));
		}
		
		PageInfo<DataDictionary> pageInfo = new PageInfo<>(resultList);
		return pageInfo;
	}*/

//	@Override
//	public List<DataDictionary> getChildrenById(DataDictionary dto) {
//		return dataDictionaryMapper.getChildrenById(dto);
//	}

	@Override
	public Integer add(DataDictionary dataDictionary) {
		return dataDictionaryMapper.add(dataDictionary);
	}

	@Override
	public DataDictionary getById(DataDictionary dataDictionary) {
		return dataDictionaryMapper.getById(dataDictionary);
	}

	@Override
	public Integer update(DataDictionary dataDictionary) {
		return dataDictionaryMapper.update(dataDictionary);
	}

	@Override
	public Integer del(DataDictionary dataDictionary) {
		return dataDictionaryMapper.del(dataDictionary);
	}
	
	
}
